import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:qq/home_page.dart';  // 导入 HomePage 文件

void main() {
  testWidgets('HomePage displays user nickname and avatar', (WidgetTester tester) async {
    // 模拟昵称和头像路径
    const String testNickname = '太阳星神';
    const String testAvatarPath = 'images/1.jpg';

    // 构建 HomePage 小部件
    await tester.pumpWidget(
      const MaterialApp(
        home: HomePage(nickname: testNickname, avatarPath: testAvatarPath),
      ),
    );

    // 1. 验证 AppBar 中是否显示昵称
    expect(find.text(testNickname).first, findsOneWidget); // 检查昵称是否在 AppBar 上

    // 2. 验证头像是否显示
    expect(find.byType(CircleAvatar).first, findsOneWidget); // 确保页面中有 CircleAvatar 小部件

    // 3. 验证头像是否加载了指定的图片
    final avatarFinder = find.byType(CircleAvatar).first;
    final CircleAvatar avatarWidget = tester.widget(avatarFinder) as CircleAvatar;
    final AssetImage avatarImage = avatarWidget.backgroundImage as AssetImage;
    expect(avatarImage.assetName, testAvatarPath); // 检查是否加载了正确的头像路径
  });
}
